import { web3Accounts, web3Enable, web3AccountsSubscribe } from '@polkadot/extension-dapp';
 
// 连接钱包
async function connectWallet() {
  const accounts = await web3Accounts();
  const injected = accounts.find(({ meta }) => meta.source === 'polkadot-js');
 
  if (injected) {
    const allAccounts = await web3AccountsSubscribe(injected.meta.source);
    console.log('Connected wallet:', allAccounts);
  } else {
    console.error('No injected polkadot-js extension found');
  }
}
 
// 断开钱包
async function disconnectWallet(name:string) {
  try {
    await web3Enable(name);
    console.log('Wallet disconnected');
  } catch (error) {
    console.error('Error disconnecting wallet:', error);
  }
}
 
// 调用函数
export default {
    connectWallet, // 连接钱包
    disconnectWallet // 断开钱包
}
